﻿<!--revision $Id$-->
<Window x:Class="ColumnChartControlSample.ColumnChartWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:parts="clr-namespace:OpenWPFChart.Parts;assembly=OpenWPFChart.Parts"
    xmlns:ctrls="clr-namespace:OpenWPFChart.Controls;assembly=OpenWPFChart.Controls"
    xmlns:helpers="clr-namespace:OpenWPFChart.Helpers;assembly=OpenWPFChart.Helpers"
	xmlns:local="clr-namespace:ColumnChartControlSample"
	Name="mainWindow"
    Title="ColumnChart Control Sample" MinWidth="300" MinHeight="300" SizeToContent="WidthAndHeight">

	<Window.InputBindings>
		<KeyBinding Key="Add" Modifiers="Control" CommandParameter="1.2" Command="NavigationCommands.Zoom" />
		<KeyBinding Key="Subtract" Modifiers="Control" CommandParameter="-1.2" Command="NavigationCommands.Zoom" />
	</Window.InputBindings>
	<Window.CommandBindings>
		<CommandBinding Command="ApplicationCommands.Open" Executed="OpenCommandHandler"/>
		<CommandBinding Command="NavigationCommands.Zoom" Executed="ZoomCommandHandler"/>
		<CommandBinding Command="ApplicationCommands.Properties" Executed="PropertiesExecutedCommandHandler"
						CanExecute="PropertiesCanExecuteCommandHandler"/>
	</Window.CommandBindings>

	<Window.Resources>
		<ContextMenu x:Key="chartItemCtxMnu">
			<MenuItem Header="Properties" Command="ApplicationCommands.Properties"/>
		</ContextMenu>

		<Style TargetType="{x:Type ctrls:ColumnChart}">
			<Setter Property="BorderBrush" Value="Cornsilk"/>
			<Setter Property="BorderThickness" Value="5"/>
			<Setter Property="Background">
				<Setter.Value>
					<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
						<GradientStop Color="BurlyWood" Offset="0"/>
						<GradientStop Color="White" Offset="1" />
					</LinearGradientBrush>
				</Setter.Value>
			</Setter>
		</Style>

		<helpers:IntegerToBoolConverter x:Key="ItemCountToBool"/>
		<helpers:IntegerToVisibilityConverter x:Key="ItemCountToVisibility"/>

		<!-- Item decorations list -->
		<!-- Default PointMarker Geometry - Circle -->
		<EllipseGeometry x:Key="markerGeometry" Center="0,0" RadiusX="4" RadiusY="4"/>
		<x:ArrayExtension x:Key="itemDecorations" Type="local:ItemDecorations">
			<local:ItemDecorations>
				<local:ItemDecorations.CurvePen>
					<Pen Brush="Brown" Thickness="1"/>
				</local:ItemDecorations.CurvePen>
				<local:ItemDecorations.PointMarker>
					<GeometryDrawing Geometry="{StaticResource markerGeometry}" Brush="Black">
						<GeometryDrawing.Pen>
							<Pen Brush="Brown" Thickness="1"/>
						</GeometryDrawing.Pen>
					</GeometryDrawing>
				</local:ItemDecorations.PointMarker>
				<local:ItemDecorations.ColumnBrush>
					<SolidColorBrush Color="Brown"/>
				</local:ItemDecorations.ColumnBrush>
			</local:ItemDecorations>
			<local:ItemDecorations>
				<local:ItemDecorations.CurvePen>
					<Pen Brush="Blue" Thickness="1"/>
				</local:ItemDecorations.CurvePen>
				<local:ItemDecorations.PointMarker>
					<GeometryDrawing Geometry="{StaticResource markerGeometry}" Brush="Blue">
						<GeometryDrawing.Pen>
							<Pen Brush="Blue" Thickness="1"/>
						</GeometryDrawing.Pen>
					</GeometryDrawing>
				</local:ItemDecorations.PointMarker>
				<local:ItemDecorations.ColumnBrush>
					<SolidColorBrush Color="Blue"/>
				</local:ItemDecorations.ColumnBrush>
			</local:ItemDecorations>
			<local:ItemDecorations>
				<local:ItemDecorations.CurvePen>
					<Pen Brush="Green" Thickness="1"/>
				</local:ItemDecorations.CurvePen>
				<local:ItemDecorations.PointMarker>
					<GeometryDrawing Geometry="{StaticResource markerGeometry}" Brush="Green">
						<GeometryDrawing.Pen>
							<Pen Brush="Green" Thickness="1"/>
						</GeometryDrawing.Pen>
					</GeometryDrawing>
				</local:ItemDecorations.PointMarker>
				<local:ItemDecorations.ColumnBrush>
					<SolidColorBrush Color="Green"/>
				</local:ItemDecorations.ColumnBrush>
			</local:ItemDecorations>
			<local:ItemDecorations>
				<local:ItemDecorations.CurvePen>
					<Pen Brush="Magenta" Thickness="1"/>
				</local:ItemDecorations.CurvePen>
				<local:ItemDecorations.PointMarker>
					<GeometryDrawing Geometry="{StaticResource markerGeometry}" Brush="Magenta">
						<GeometryDrawing.Pen>
							<Pen Brush="Magenta" Thickness="1"/>
						</GeometryDrawing.Pen>
					</GeometryDrawing>
				</local:ItemDecorations.PointMarker>
				<local:ItemDecorations.ColumnBrush>
					<SolidColorBrush Color="Magenta"/>
				</local:ItemDecorations.ColumnBrush>
			</local:ItemDecorations>
			<local:ItemDecorations>
				<local:ItemDecorations.CurvePen>
					<Pen Brush="Red" Thickness="1"/>
				</local:ItemDecorations.CurvePen>
				<local:ItemDecorations.PointMarker>
					<GeometryDrawing Geometry="{StaticResource markerGeometry}" Brush="Red">
						<GeometryDrawing.Pen>
							<Pen Brush="Red" Thickness="1"/>
						</GeometryDrawing.Pen>
					</GeometryDrawing>
				</local:ItemDecorations.PointMarker>
				<local:ItemDecorations.ColumnBrush>
					<SolidColorBrush Color="Red"/>
				</local:ItemDecorations.ColumnBrush>
			</local:ItemDecorations>
		</x:ArrayExtension>
	</Window.Resources>

	<DockPanel>
		<!-- Menu -->
		<Menu DockPanel.Dock="Top">
			<MenuItem Header="_File">
				<MenuItem Command="Open" Name="mnuFileOpen"/>
				<Separator/>
				<MenuItem Header="_Recent Files" Name="mnuRecentFiles"/>
				<Separator/>
				<MenuItem Header="_Exit" Click="Exit_Click"/>
			</MenuItem>
			<MenuItem Header="_View" IsEnabled="{Binding ElementName=chart, Path=Items.Count,
				Converter={StaticResource ItemCountToBool}}">
				<MenuItem Header="_Horizontal Axis Properties" Name="hAxisPropertiesMnuItem" Click="mnuViewAxisProperties_Click"/>
				<MenuItem Header="_Vertical Axis Properties" Name="vAxisPropertiesMnuItem" Click="mnuViewAxisProperties_Click"/>
				<Separator/>
				<MenuItem Header="Swap Horizontal Scale"
						  Command="{Binding ElementName=mainWindow, Path=SwapLinLogScaleCommand}"/>
				<MenuItem Header="Swap Vertical Scale"
						  Command="{Binding ElementName=mainWindow, Path=SwapLinLogScaleCommand}"
						  CommandParameter="Vertical"/>
				<Separator/>
				<MenuItem Header="Zoom_In (Ctrl+NumPad+)" Command="Zoom" CommandParameter="1.2"/>
				<MenuItem Header="Zoom_Out (Ctrl+NumPad-)" Command="Zoom" CommandParameter="-1.2"/>
			</MenuItem>
		</Menu>

		<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
			<Grid>
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto"/>
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>

				<!-- Chart -->
				<ctrls:ColumnChart Name="chart" 
					parts:Item.MouseEnterItem="chartItem_EnterItem"
					parts:Item.MouseLeaveItem="chartItem_LeaveItem"
					IsSynchronizedWithCurrentItem="True"
					ContextMenu="{StaticResource chartItemCtxMnu}"
					Padding="3"
					parts:Axis.FontWeight="Bold"
					SnapsToDevicePixels="true" 
					HorizontalGridFill="Azure"
								   >

					<!--<parts:Axis.Pen>
						<Pen Brush="Green" Thickness="1"/>
					</parts:Axis.Pen>
					<parts:Grid.Pen>
						<Pen Brush="Green" Thickness="0.3">
							<Pen.DashStyle>
								<DashStyle Dashes="8,10,0,2"/>
							</Pen.DashStyle>
						</Pen>
					</parts:Grid.Pen>-->

					<ctrls:ColumnChart.HorizontalScale>
						<parts:ChartLinearScale Start="0" Stop="260" TickStep="10"/>
					</ctrls:ColumnChart.HorizontalScale>
					<ctrls:ColumnChart.VerticalScale>
						<parts:ChartLinearScale Start="0" Stop="250" TickStep="10"/>
					</ctrls:ColumnChart.VerticalScale>
				</ctrls:ColumnChart>

				<!-- Legend -->
				<ctrls:ChartLegend
					ItemsSource="{Binding ElementName=chart, Path=ItemsSource}"
					SelectedItem="{Binding ElementName=chart, Path=SelectedItem}"
					IsSynchronizedWithCurrentItem="True"
					Visibility="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Items.Count,
						Converter={StaticResource ItemCountToVisibility}}"
					BorderBrush="Cornsilk" BorderThickness="5" CornerRadius="5" Background="White"
					Margin="20" HorizontalAlignment="Right" VerticalAlignment="Top"
					/>
			</Grid>
		</ScrollViewer>
	</DockPanel>
</Window>
